package com.my.ph.controller;

import com.my.ph.entity.file.FileInfo;
import com.my.ph.service.FileDirectoryService;
import com.my.ph.util.R;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/fileDirectory")
@RequiredArgsConstructor
public class FileDirectoryController {

    private final FileDirectoryService fileDirectoryService;

    @GetMapping("/root")
    public R<List<FileInfo>> root() {
        return R.ok(fileDirectoryService.getRoot());
    }

    @PostMapping("/children")
    public R<List<FileInfo>> children(@RequestBody FileInfo fileInfo) {
        return R.ok(fileDirectoryService.getChildren(fileInfo.getFilePath()));
    }

    @GetMapping("/getTorrent")
    public void getTorrent(String torrentPath, HttpServletResponse response) throws IOException {
        fileDirectoryService.getTorrent(torrentPath, response);
    }

}
